package com.atguigu;

import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.Region;
import com.qiniu.storage.model.BatchStatus;
import com.qiniu.util.Auth;

import java.util.ArrayList;
import java.util.List;

public class qiniuTestDeleteList {
    final static String accessKey = "TYHMVuGpxupDATQaYERN8fPzBllC8MWuzjoGsjlE";
    final static String secretKey = "3tGcgqra7-FRnYFevt8UmFlXPG9KlMWLyEjr7TOy";
    final static String bucket = "classroomtest";
    public static void main(String[] args) {
        List<String> myFile=new ArrayList<>();
        myFile.add("aaa");
        String s=util(myFile);
        System.out.println(s);
    }
    static String  util(List<String> myFile){
        Auth auth=Auth.create(accessKey,secretKey);
        Configuration cfg=new Configuration(Region.region1());
        BucketManager bucketManager=new BucketManager(auth,cfg);
        BucketManager.BatchOperations batchOperations=new BucketManager.BatchOperations();
        String[] files=new String[myFile.size()];
        batchOperations.addDeleteOp(bucket, myFile.toArray(files));
        try {
            Response response = bucketManager.batch(batchOperations);
//            BatchStatus[] batchStatusList = response.jsonToObject(BatchStatus[].class);
//            for (int i = 0; i < myFile.size(); i++) {
//                BatchStatus status = batchStatusList[i];
//                String key = files[i];
//                System.out.print(key + "\t");
//                if (status.code == 200) {
//                    System.out.println("delete success");
//                } else {
//                    System.out.println(status.data.error);
//                }
//            }
        } catch (QiniuException e) {
            e.printStackTrace();
        }
        return null;
    }
}
